import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:safetymonitor/app/core/values/gaps.dart';

/// 通用自适应的dialog
/// ```
///  Get.dialog(CommonAdaptiveTips(
///  contentWidget:Container()
///    func: (bool b) {
///    },
///  ));
/// ```
class CommonAdaptiveDialog extends StatelessWidget {
  const CommonAdaptiveDialog({
    required this.func,
    super.key,
    this.contentWidget,
    this.title,
  });

  // 标题
  final String? title;

  final Widget? contentWidget;

  final Function(bool b) func;

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: 20.w),
      alignment: Alignment.center,
      child: Container(
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.all(Radius.circular(10.w)),
        ),
        child: SingleChildScrollView(
          child: IntrinsicHeight(
            child: Stack(
              children: [
                Container(
                    padding:
                        EdgeInsets.symmetric(horizontal: 20.w, vertical: 18.w),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          title ?? '提示',
                          style: TextStyle(
                              color: const Color(0xFF1D3452),
                              fontSize: 18.sp,
                              fontWeight: FontWeight.w500),
                        ),
                        contentWidget ?? Container(),
                        AppGaps.vGap14,
                        Row(
                          children: [
                            Expanded(
                                child: ElevatedButton(
                              style: ButtonStyle(
                                backgroundColor: MaterialStateProperty.all(
                                    const Color(0xFFC2CEF7)),
                              ),
                              child: Text(
                                '取消',
                                style: TextStyle(
                                    fontSize: 16.sp,
                                    color: const Color(0xFF1847E3)),
                              ),
                              onPressed: () {
                                Navigator.pop(context);
                              },
                            )),
                            AppGaps.hGap14,
                            Expanded(
                                child: ElevatedButton(
                              style: ButtonStyle(
                                backgroundColor: MaterialStateProperty.all(
                                    const Color(0xff5C6DFF)),
                              ),
                              child: Text(
                                '确认$title',
                                style: TextStyle(
                                    fontSize: 16.sp, color: Colors.white),
                              ),
                              onPressed: () {
                                func(true);
                                // Navigator.pop(context);
                              },
                            )),
                          ],
                        )
                      ],
                    )),
                Positioned(
                    top: 0,
                    right: 0,
                    child: IconButton(
                      icon: Container(
                        width: 30.w,
                        height: 30.w,
                        decoration: BoxDecoration(
                          color: Colors.white,
                          borderRadius: BorderRadius.all(Radius.circular(15.w)),
                        ),
                        child: Icon(
                          Icons.close,
                          color: Colors.black,
                          size: 21.w,
                        ),
                      ),
                      onPressed: () {
                        func(false);
                        Navigator.pop(context);
                      },
                    ))
              ],
            ),
          ),
        ),
      ),
    );
  }
}
